<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@  taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<%@include file="common/head.jsp"%>

<body class="fix-header fix-sidebar">

	<!-- Preloader - style you can find in spinners.css -->
	<div class="preloader">
		<svg class="circular" viewBox="25 25 50 50">
				<circle class="path" cx="50" cy="50" r="20" fill="none"
				stroke-width="2" stroke-miterlimit="10" /> </svg>
	</div>
	<!-- Main wrapper  -->
	<div id="main-wrapper">
		<!-- header header  -->
		<%@ include file="common/header.jsp"%>
		<!-- End header header -->
		<!-- Left Sidebar  -->
		<%@ include file="common/nav.jsp"%>
		<!-- End Left Sidebar  -->
		<!-- Page wrapper  -->
		<div class="page-wrapper">
			<!-- 锐高软件 -->
			<%@ include file="../common/ruigao.jsp"%>

			<!--
                    	作者：offline
                    	时间：2018-03-26
                    	描述：添加部门信息
                    -->

			<div class="container-fluid">
				<!-- Start Page Content -->
				<div class="row justify-content-center">
					<div class="col-lg-12">
						<div class="card">
							<div class="card-body">
								<div class="card-content">
									<!-- Left sidebar -->
									<div class="inbox-leftbar">

										<a href="${pageContext.request.contextPath}/departshowlist"
											class="btn btn-danger btn-block waves-effect waves-light">
											<font style="vertical-align: inherit;"> <font
												style="vertical-align: inherit;">部门列表</font>
										</font>
										</a>
									</div>
									<!-- End Left sidebar -->
									<div class="inbox-rightbar">
										<div class="" role="toolbar">
											<div class="btn-group">
												<button type="button" class="btn btn-light waves-effect">
													<i class="mdi mdi-archive font-18 vertical-middle"></i>
												</button>
												<button type="button" class="btn btn-light waves-effect">
													<i class="mdi mdi-alert-octagon font-18 vertical-middle"></i>
												</button>
												<button type="button" class="btn btn-light waves-effect">
													<i class="mdi mdi-delete-variant font-18 vertical-middle"></i>
												</button>
											</div>

											<div class="btn-group">
												<button type="button"
													class="btn btn-light dropdown-toggle waves-effect"
													data-toggle="dropdown" aria-expanded="false">
													<font style="vertical-align: inherit;"><font
														style="vertical-align: inherit;"> 更多 </font></font><span
														class="caret m-l-5"></span>
												</button>
												<div class="dropdown-menu">

													<a class="dropdown-item" href="javascript: void(0);">1</a>
													<a class="dropdown-item" href="javascript: void(0);">2</a>
													<a class="dropdown-item" href="javascript: void(0);">3</a>
													<a class="dropdown-item" href="javascript: void(0);">4</a>

												</div>

											</div>

										</div>
									</div>
								</div>
							</div>
							<div class="form-validation">
								<form class="form-valide col-lg-8" id="form" novalidate="novalidate" style="margin: 0 auto;">

									<%@ include file="../listall/selectcompanyname.jsp"%>
									<div class="form-group row">
										<label class="col-lg-2 col-form-label" for="val-name">部门名称</label>
										<div class="col-lg-10">
											<input type="text" class="form-control" id="val-name"
												name="val-name" placeholder="输入部门名称">
										</div>
									</div>
									
									
									<div class="form-group row">
										<label class="col-lg-2 col-form-label" for="val-name">部门负责人</label>
										<div class="col-lg-10">
											<select class="form-control" id="val-principal" name="val-principal">
												
											</select>
										</div>
									</div>
									<div class="form-group row">
										<label class="col-lg-2 col-form-label" for="val-phone">部门电话</label>
										<div class="col-lg-10">
											<input type="text" class="form-control" id="val-phone"
												name="val-phone" placeholder="输入电话">
										</div>
									</div>
									<div class="form-group row">
										<label class="col-lg-2 col-form-label" for="val-skill">部门描述</label>
										<div class="col-lg-10">
											<textarea name="val-deptBlurb" id="val-skill" rows="2"
												cols="60" class="form-control" style="height: 100px;"></textarea>
										</div>
									</div>
									<div class="form-group row">
										<div class="col-lg-8 ml-auto">
											<button type="button"
												class="btn btn-success btn sweet-tijiao deptadd">创建</button>
											<input type="hidden" name="dept" value="" id="deptadd">
											<button type="reset" class="btn btn-primary ">重置</button>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- End Container fluid  -->
	<!-- footer -->
	<%@ include file="common/footer.jsp"%>
	<!-- End footer -->
	<!-- End Page wrapper  -->
	<%@ include file="common/js.jsp"%>
	<script type="text/javascript">
		$(function() {
			//点击初始化
			var options = $("#val-company option:selected");
    		var companyid= parseInt(options.val());
    	    $.ajax({
    	    	url:"userGetByCompany",
    	    	data:{"companyid":companyid},
    	    	type:"GET",
    	    	dataType:"json",
    	    	success:function(data){
    	        	$("#val-principal").text("");
    	        	for(var i in data){
    	       			$("#val-principal").append("<option value="+data[i].userId+">"+data[i].userName+"</option>");
    	        	}
    	    	},
    	    		error:function(data){
    	    		 swal({
 			            title:'操作失败！',		           
 			            type:'error',
 			            confirmButtonText:'确定',
 			            closeOnConfirm:false
 			         });
    	    	}
    	    });
			 //获取选择的公司
	    	$("#val-company").change(function(){
	    		var options = $("#val-company option:selected");
	    		var companyid= parseInt(options.val());
	    	    $.ajax({
	    	    	url:"userGetByCompany",
	    	    	data:{"companyid":companyid},
	    	    	type:"GET",
	    	    	dataType:"json",
	    	    	success:function(data){
	    	        	$("#val-principal").text("");
	    	        	for(var i in data){
	    	       			$("#val-principal").append("<option value="+data[i].userId+">"+data[i].userName+"</option>");
	    	        	}
	    	    	},
	    	    		error:function(data){
	    	    		 swal({
	 			            title:'操作失败！',		           
	 			            type:'error',
	 			            confirmButtonText:'确定',
	 			            closeOnConfirm:false
	 			         });
	    	    	}
	    	    });
	    	});
			 //添加部门
			$(".deptadd").click(function() {
				$("#deptadd").val("deptadd");			
				$.ajax({
					url : "deptservlet",
					type : "POST",
					data : $("#form").serialize(),
					success : function(data) {
						if (data) {
							swal({
								title : "创办成功!",
								type : 'success',
								text : "是否返回列表查看？",
								showCancelButton : true,
								closeOnConfirm : false,
								cancelButtonText : "取消",
								confirmButtonText : "确定"
								},
								function(inputValue) {
									if (inputValue === true) {
										location.href = "${pageContext.request.contextPath}/departshowlist";
									} else {
										return false;
									}
								});
							}else{
								swal({
									title : '创办失败！',
									type : 'error',
									confirmButtonText : '确定',
									closeOnConfirm : false
								});
							}
						},
						error : function(data) {
							swal({
								title : '创办失败！',
								type : 'error',
								confirmButtonText : '确定',
								closeOnConfirm : false
							});
						}
					});
				});
			});
	</script>
</body>

</html>